package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.bo.WxReceiveBO;
import com.cskaoyan.bean.pojo.MallCoupon;
import com.cskaoyan.bean.vo.ExchangeCode;
import com.cskaoyan.bean.WxBaseData;
import com.cskaoyan.bean.bo.WxCouponBO;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.CouponBaseVO;
import com.cskaoyan.bean.vo.WxCouponList;
import com.cskaoyan.service.WxCouponService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Chunlai
 * @description:
 * @time: 2021/7/11 22:14
 */
@RestController
@RequestMapping("wx/coupon")
public class WxCouponController {

    @Autowired
    WxCouponService wxCouponService;


    @GetMapping("mylist")
    public BaseRespVo mylist(WxCouponBO wxCouponBO){

        WxBaseData wxBaseData=wxCouponService.selectCouponInfos(wxCouponBO);
        return BaseRespVo.ok(wxBaseData);
    }

    @GetMapping("list")
    public BaseRespVo list(WxCouponBO wxCouponBO){
        WxBaseData wxBaseDataCouponUnUsed =wxCouponService.selectCouponUnUsed(wxCouponBO);
        return BaseRespVo.ok(wxBaseDataCouponUnUsed);
    }

    @PostMapping("receive")
    public CouponBaseVO receive(@RequestBody WxReceiveBO wxReceiveBO){
        int index = wxCouponService.insertReceiveById(wxReceiveBO);
        if (index == 200){
            return CouponBaseVO.ok();
        }
        if (index == 101){
            return CouponBaseVO.over2();
        }
        return CouponBaseVO.ok();
    }

    @PostMapping("exchange")
    public CouponBaseVO exchange(@RequestBody ExchangeCode exchangeCode){
        int index = wxCouponService.insertCouponById(exchangeCode);
        if (index == 200){
            return CouponBaseVO.ok();
        }
        if (index == 101){
            return CouponBaseVO.over();
        }
        if (index == 404){
            return CouponBaseVO.fail();
        }
        return CouponBaseVO.ok();
    }

    @GetMapping("selectlist")
    public BaseRespVo selectlist(Integer cartId ,Integer grouponRulesId){
        List<WxCouponList> wxCouponLists = wxCouponService.selectlist(cartId);
        return BaseRespVo.ok(wxCouponLists);
    }

}